import time
import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.action_chains import ActionChains


class MyTestCaseFireFox(unittest.TestCase):
    driver = None

    @classmethod
    def setUpClass(cls) -> None:
        # 注册 驱动打开的位置
        service = Service(executable_path="../../dirver_exe/geckodriver.exe")
        # 打开浏览器  driver 代表 浏览器对象
        cls.driver = webdriver.Firefox(service=service)

    def test_baidu(self):
        self.driver.get("https://www.baidu.com")

        news = self.driver.find_elements(By.XPATH, "//span[@class='title-content-title']")
        news[0].click()

    def test_doubleClick(self):
        self.driver.get("http://192.168.0.152:8080/testhtml/exam/House.html")

        text = self.driver.find_element(By.NAME, "username")
        # 双击可以通过 事件 来完成
        ActionChains(self.driver).double_click(text).perform()

    @classmethod
    def tearDownClass(cls) -> None:
        # cls.driver.close()  # 只会关闭一个标签页
        # cls.driver.quit()  # 直接退出浏览器 并且关闭所有的标签页
        pass


if __name__ == '__main__':
    unittest.main()
